package com.zhaofan.other;

import org.junit.Test;

import java.util.HashSet;

public class No3 {
    @Test
    public void test1(){
        String s="cdd";
        System.out.println(lengthOfLongestSubstring(s));
    }


    public int lengthOfLongestSubstring(String s) {
        int rk=-1,max=0;
        HashSet<Character> set = new HashSet<>();
        for(int i=0;i<s.length();i++){
            while(rk+1<s.length()&&!set.contains(s.charAt(rk+1))){
                set.add(s.charAt(rk+1));
                rk++;
            }
            max=Math.max(max,rk-i+1);
            set.remove(s.charAt(i));
        }
        return max;
    }

    @Test
    public void test(){
        try{
            throw new NullPointerException();
        }catch (Exception e){
            System.out.println("null");
        }
    }
}
